const { app, BrowserWindow, ipcMain } = require('electron')
const isDev = require('electron-is-dev');
function init() {
  const win = new BrowserWindow({
    width: 800,
    height: 500,
    webPreferences: {
      contextIsolation: false,
      nodeIntegration: true
    }
  })
  require('@electron/remote/main').initialize() // 初始化
  require('@electron/remote/main').enable(win.webContents)
  const url = isDev ? 'http://localhost:3000' : 'https://baidu.com'
  win.loadURL(url)
  win.webContents.openDevTools()
}

function ipc() {
  ipcMain.handle('login', async () => {
    // mock一个状态码
    const code = Math.floor(Math.random() * (999999 - 100000)) + 100000;
    return code;
  })
}

app.on('ready', function () {
  // process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'//关闭web安全警告
  init()
  ipc()
})